package com.ssis.core;

public class CrewStat {
	private String name;
	private int level;
	private int xp;
	private static final int XP_PER_LEVEL_BASE = 100;
	
	public CrewStat(String name) {
		this.name = name;
		this.level = 0;
		this.xp = 0;
	}
	
	/**
	 * Add XP to skill and check for level up
	 * @param amount of XP to add
	 * @return true iff levels up
	 */
	public boolean addXP(int amount) {
		this.xp += amount;
		if(xp > XP_PER_LEVEL_BASE * level) {
			while (xp > XP_PER_LEVEL_BASE * level) {
				xp -= XP_PER_LEVEL_BASE * level;
				level++;
			}
			return true;
		}
		return false;
	}
	
	public String name() {
		return name;
	}
	
	public int level() {
		return level;
	}
	
	public int xp() {
		return xp;
	}
	
	public int xpPercent() {
		return xp / (XP_PER_LEVEL_BASE * level);
	}
}
